//
//  JZHNoteViewController.m
//  极致荟
//
//  Created by hetao on 14-5-15.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHNoteViewController.h"
#import "OtherUsersDao.h"
#import "JZHContactsViewController.h"
#import "JZHChatViewController.h"
@interface JZHNoteViewController ()
{
    NSArray *arrdata;
}
@property (weak, nonatomic) IBOutlet UITableView *table;

@end

@implementation JZHNoteViewController

- (id)initOuser:(OtherUsers *)ouser
{
    JZHNoteViewController *jzh=[[JZHNoteViewController alloc] init];
    jzh.ouser=ouser;
    return jzh;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
    arrdata=[OtherUsersDao selectNoteMessage];
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setFont:[UIFont systemFontOfSize:14]];
    [leftButton setTitleColor:TEXTBULE forState:UIControlStateNormal];
    [leftButton setTitle:@"取消" forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;

}
- (IBAction)pus:(id)sender
{
    [self.navigationController pushViewController:[[JZHContactsViewController alloc] initIsPusNote:self.ouser farr:nil] animated:YES];
}

- (void)leftDrawerButtonPress:(UIButton *)but
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark ---tableview代理---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return arrdata.count;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    
    return @"最近聊天";
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str=@"adf";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
    if(!cell)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
       
    }
     cell=[self addViewCell:cell indexpath:indexPath];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:[[JZHChatViewController alloc] initOuser:arrdata[indexPath.row] Recommend:self.ouser] animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}
///向Cell添加控件

- (UITableViewCell *)addViewCell:(UITableViewCell *)cell indexpath:(NSIndexPath *)index
{
    OtherUsers *ousers=arrdata[index.row];
    UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(14, 10, 40, 40)];
    [image.layer setCornerRadius:6 ];
    [image.layer setMasksToBounds:YES];
    [image setImage:[UIImage imageNamed:@"详细资料照片"]];
    [ImageCache imageUrl:ousers.userHeadImage UiImageview:image];
    [cell.contentView addSubview:image];
    
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(70, 16, 200, 21)];
    if(ousers.bname.length!=0)
    {
        [lable setText:ousers.bname];
    }else
    {
        [lable setText:ousers.name];
    }
    
    [lable setFont:[UIFont systemFontOfSize:14]];
    [cell.contentView addSubview:lable];
    return cell;
}
@end
